import { Component, OnInit } from '@angular/core';

@Component({
    selector: 'app-time-dom',
    templateUrl: './dom.component.html',
    styleUrls: ['./dom.component.scss']
})
export class TimeDomComponent implements OnInit {
    startTime: any;
    constructor() { }

    ngOnInit(): void {
        document.getElementById('hold').addEventListener('mousedown', () => {
            this.startTime = new Date();
        });

        document.getElementById('hold').addEventListener('mouseup', () => {
            if (this.startTime) {
                let endTime: any = new Date();
                const elapsedMillSeconds = endTime - this.startTime;
                document.getElementById('time').textContent = elapsedMillSeconds.toString();        
            }
        });
    }
}
